#include <stdio.h>
#include <stdlib.h>
#include <crtdbg.h>
#include "readwave.h"
#include "lpc.h"

void main(int argc, char **argv)
{

#ifdef _DEBUG
//	_CrtSetBreakAlloc(0);
#endif

	int i,j;
	
	char filename[256];
	strcpy(filename, argv[1]);
	
	int numSamples, nSmpRate;
	WavHead wavhead;
	short *WaveData = ReadWave(filename, &numSamples, &wavhead);
	nSmpRate = wavhead.SampleRate;
	
	
	FEATURE_LPCBASEINFO p_info;
	LPC lpc;
	strcpy(p_info.targetKind,"LPC");
	lpc.Initialize(p_info);
	
	int nFrmNum = lpc.GetFrameNum(numSamples);

	float *LPC_FeatBuf=new float[nFrmNum*lpc.m_nFeatDim];
	ASSERT3(LPC_FeatBuf,"Error new pFeatBuf [%d]!",nFrmNum*lpc.m_nFeatDim);
	lpc.ComputeLPC(WaveData,numSamples,LPC_FeatBuf);
		
	
	FILE *fp = fopen("lpc.txt","w");
	
	for (i=0; i<nFrmNum; i++)
	{
		for (j=0; j<lpc.m_nFeatDim; j++)
		{
			fprintf(fp,"%.2f\t", (float)LPC_FeatBuf[i*lpc.m_nFeatDim+j]);
		}
		fprintf(fp,"\n");
	}
	
	fclose(fp);

	delete []WaveData;
	delete []LPC_FeatBuf;

#ifdef _DEBUG
	_CrtDumpMemoryLeaks();
#endif

}